/**
* 系统管理 用户管理
*/
<template>


  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>结果配置详情</el-breadcrumb-item>
    </el-breadcrumb>

    <div style="padding:5px;color:#000000;text-align: center;font-family:PingFang SC;font-size:30px">结果存储配置列表</div>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="">
        <el-input size="small" @keyup.enter="getList(formInline)"  v-model="formInline.taskName" placeholder="输入任务名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="getList(formInline)">搜索</el-button>
<!--        <el-button size="small" type="info" icon="el-icon-refresh" @click="reset">重置</el-button>-->
        <el-button size="small" type="success" icon="el-icon-plus" @click="addTask">新增</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" @selection-change="selectChange" :data="dataCleanTaskList" highlight-current-row v-loading="loading" border element-loading-text="执行任务中" style="width: 100%;">
      <el-table-column v-if="false" align="center" type="selection" width="40">
      </el-table-column>
      <el-table-column align="center" sortable prop="id" v-if="false" label="序号" width="90">
      </el-table-column>
      <el-table-column align="center" prop="storeName" label="存储配置名称" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="storeType" label="数据源类型" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="datastore" label="数据源" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="datastoreTable" label="数据表" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="datastoreFiled" label="数据表字段" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="url" label="url" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="userName" label="用户" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="pwd" label="密码" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="port" label="端口" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="path" label="存储路径" width="150">
      </el-table-column>


      <!--操作-->
      <el-table-column align="center" label="操作" min-width="300">
        <template slot-scope="scope">
<!--          <el-button size="mini" type="success" @click="detail(scope.row.id)">详情</el-button>-->
          <el-button size="mini" type="success" @click="detail(scope.row)">修改</el-button>

          <el-button size="mini" type="danger" @click="deleteTask(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 编辑界面 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="30%" @click="closeDialog">
      <el-form label-width="120px" :model="editForm"  ref="editForm">
        <el-form-item label="结果配置名称" prop="deptName">
          <el-input size="mini" v-model="ef.storeName" auto-complete="off" placeholder="" @blur="lossFocus"></el-input>
        </el-form-item>
        <el-form-item label="数据源类型" prop="deptName">
          <el-input size="mini" v-model="ef.storeType" auto-complete="off" placeholder="" @blur="lossFocus"></el-input>
        </el-form-item>
        <el-form-item label="数据源" prop="deptName">
          <el-input size="mini" v-model="ef.datastore" auto-complete="off" placeholder="" @blur="lossFocus"></el-input>
        </el-form-item>
        <el-form-item label="数据源表" prop="deptName">
          <el-input size="mini" v-model="ef.datastoreTable" auto-complete="off" placeholder="" @blur="lossFocus"></el-input>
        </el-form-item>
        <el-form-item label="数据源字段" prop="deptName">
          <el-input size="mini" v-model="ef.datastoreFiled" auto-complete="off" placeholder="" @blur="lossFocus"></el-input>
        </el-form-item>
        <el-form-item label="存储路径" prop="deptName">
          <el-input size="mini" v-model="ef.path" auto-complete="off" placeholder="" @blur="lossFocus"></el-input>
        </el-form-item>
        <el-form-item label="端口" prop="deptName">
          <el-input size="mini" v-model="ef.port" auto-complete="off" placeholder="" @blur="lossFocus"></el-input>
        </el-form-item>
        <el-form-item label="url" prop="deptName">
          <el-input size="mini" v-model="ef.url" auto-complete="off" placeholder="" @blur="lossFocus"></el-input>
        </el-form-item>
        <el-form-item label="用户名" prop="deptName">
          <el-input size="mini" v-model="ef.userName" auto-complete="off" placeholder="" @blur="lossFocus"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="deptName">
          <el-input size="mini" v-model="ef.pwd" auto-complete="off" placeholder="" @blur="lossFocus"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog">取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('editForm')">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 导入请求方法

import Pagination from '../../components/Pagination'
import axios from "axios";

import UnStructDataMan from "../dataManage/UnStructDataMan.vue";
import AlgoConfig from "./algo-config.vue";
export default {
  data() {
    return {

      dataCleanTaskList:[],
      // 删掉

      isShow:false,
      isShow1:false,

      loading: false, //是显示加载
      title: '新增任务',
      editFormVisible: false, //控制编辑页面显示与隐藏



      // 编辑与添加
      editForm: {
        id: '',
        taskName: '',
        modeltargets:[],
        example: '',
        sourceType: '',
        sourceId: '',
        datasourceIds:[],
        tagId:'' ,
        status:'未执行',
        userId: localStorage.getItem('userId')
      },
      // 选择数据
      selectdata: [],
      // rules表单验证
      rules: {
        taskName: [
          { required: true, message: '请输入任务名称', trigger: 'blur' }
        ],
        sourceType: [{ required: true, message: '请选择数据源类型', trigger: 'blur' }],
        datasourceIds: [{ required: true, message: '请选择数据源表', trigger: 'blur' }],
        example: [{ required: true, message: '请选择执行条件', trigger: 'blur' }],


      },

      // 请求数据参数
      formInline: {
        page: 1,
        limit: 10,
        taskName: '',
        isLock: ''
      },

      ef:{
        id:'',
        createTime:'',
        datastore:'',
        datastoreFiled:'',
        datastoreTable:'',
        path:'',
        port:'',
        pwd:'',
        storeName:'',
        storeType:'',
        updataTime:'',
        url:'',
        userName:''
      },
      // 分页参数
      Data:[],
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      },

      dialogVisible: false,
      checkedData: [],

      visible: false
    }
  },
  // 注册组件
  components: {
    Pagination,
    UnStructDataMan,
    AlgoConfig
  },

  /**
   * 数据发生改变
   */
  watch: {},

  /**
   * 创建完毕
   */
  created() {
    this.data1 = localStorage.getItem('userId')
    this.getList(this.formInline)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    submitForm(){
      if(this.ef.id != null){//update操作
        let url = this.$global.javaUrl + "/DataCleaStoreConfig/saveOrUpdate"
        let config = {
          headers: {
            'user': localStorage.getItem('userId')
          }
        }
        axios.post(url, this.ef, config).then(res => {
          console.log("测试更新功能")
          console.log(res)
          this.$message({
            type: 'success',
            message: '更新成功!'
          })
          this.editFormVisible = false
          this.getList(this.formInline)
        })
      }else {//add操作

        let url = this.$global.javaUrl + "/DataCleaStoreConfig/saveOrUpdate"
        let config = {
          headers: {
            'user': localStorage.getItem('userId')
          }
        }
        axios.post(url, this.ef, config).then(res => {
          console.log("测试添加功能")
          console.log(res)
          this.$message({
            type: 'success',
            message: '添加成功!'
          })
          this.editFormVisible = false
          this.getList(this.formInline)
        })

      }
    },
    // 获取数据列表
    getList(formInline){
      this.logining = true
      let url = this.$global.javaUrl +"/DataCleaStoreConfig/list"
      let config = {
        headers:
          {
            //'Content-Type':'application/json',
            'user' : localStorage.getItem('userId')
          },
        params: {
          name:this.formInline.taskName,
          pageNum: this.formInline.page,
          pageSize:this.formInline.limit,

        }
      }

      axios.get(url, config).then(response=>{
        this.dataCleanTaskList = response.data.data.rows

        this.pageparm.total = response.data.data.records

        console.log(response.data.data.rows)

      })


    },
    // 详情
    detail(id){
      this.ef = id;
      this.editFormVisible = true;
    },
    // 删除任务
    deleteTask(id) {
      let config = {
        headers:
          {
            'Content-Type':'application/json',
            'user' : localStorage.getItem('userId')
          },
        params:{'id':id}

      }

      this.$confirm('确定要删除吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // 删除
          axios.get(this.$global.javaUrl+"\n" + "/DataCleaStoreConfig/delete",config)
            .then(res => {
              if (res.data.data !=0) {
                this.$message({
                  type: 'success',
                  message: '任务已删除!'
                })
                this.getList(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: "1111"
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('任务删除失败，请稍后再试！')
            })
          this.getSearchPage()
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除！'
          })
        })
    },

    // 执行清洗任务
    action(id) {
      let url = this.$global.javaUrl + "/dataCleanTask/actionNow"
      let config = {
        headers:
          {
            'Content-Type':'application/json',
            'user' : localStorage.getItem('userId')
          },
        params:{'id':id}

      }

      this.$confirm('确定要执行该任务吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.loading = true;
          // 删除
          axios.get(url,config)
            .then(res => {
              if (res.data.data !=0) {
                this.loading = false;
                this.$message({

                  type: 'success',
                  message: '任务执行成功!'
                })
                this.getList(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: "1111"
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('任务执行失败，请稍后再试！')
            })
          this.getList(this.formInline)
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消执行！'
          })
        })
    },

    //重置
    reset() {
      this.formInline.page = 1
      this.formInline.taskName = ""
      this.getList(this.formInline)
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getList(this.formInline)
    },
    /////////////////////////////////////////////////////////////////////
    addTask() {
      this.ef = {};
      this.editFormVisible = true;

    },






    /*

          //显示编辑界面
          handleEdit: function(index, row) {
            this.editFormVisible = true
            if (row != undefined && row != 'undefined') {
              this.title = '修改任务'
              this.editForm.id = row.id

            } else {
              this.isShow = false
              this.isShow1 = false
              this.title = '新增任务'
              this.editForm.id = ''
              this.editForm.taskName = ''
              this.editForm.example = ''
              this.editForm.sourceType = ''
              this.editForm.sourceId = ''
              this.editForm.datasourceIds =''
            }
          },
          // 编辑、添加提交方法
          submitForm(editData) {
            var cur_id = this.editForm.example;
            var cur_e = "";
            this.editForm.modelTargets = []
            for(var i = 0; i < this.exampleData.length; i++){
              if(this.exampleData[i].id == this.editForm.example){
                cur_e = this.exampleData[i].example
              }
            }
            this.editForm.modelTargets[0] = {
              id:cur_id,
              example:cur_e
            }
            if(this.editForm.sourceType == "非结构化数据源"){
              this.editForm.datasourceIds = []
              for(var i =0;i<this.checkedData.length;i++){
                this.editForm.datasourceIds[i]= this.checkedData[i]["id"]
              }
            }
            console.log("this.editForm.datasourceIds",this.editForm.datasourceIds)
            let config = {
              headers:
                {
                  'Content-Type':'application/json',
                  'user' : localStorage.getItem('userId')
                }
            }
            this.$refs[editData].validate(valid => {
              if (valid) {
                console.log("fffffffffff",this.editForm)
                // 请求方法
                axios
                  .post(this.$global.javaUrl+"/task/saveOrUpdate",this.editForm,config)
                  .then(res => {
                    this.editFormVisible = false
                    this.loading = false
                    if (res.data.data != null) {
                      this.$message({
                        type: 'success',
                        message: "数据保存成功！"
                      })
                      this.getSearchPage()
                    } else {
                      this.$message({
                        type: 'info',
                        message: res.msg
                      })
                    }
                  })
                  .catch(err => {
                    this.editFormVisible = false
                    this.loading = false
                    this.$message.error('保存失败，请稍后再试！')
                  })
              } else {
                return false
              }
            })

          },
    */


    // 选择复选框事件
    selectChange(val) {
      this.selectdata = val
    },






  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>
